home *** CD-ROM | disk | FTP | other *** search
/ MACD 5 / MACD 5.bin / workbench / libs / amigametafile.lha / AmigaMetaFormat / C / test.c < prev    next >
C/C++ Source or Header  |  1997-05-05  |  8KB  |  170 lines

  1. /*
  2. **  this code is not a example for well programming :-)
  3. **  but for use of amigametaformat.library and parsing AMF files
  4. **  compile with 'sc test LINK'
  5. */
  6.  
  7. #include <intuition/intuition.h>
  8. #include <graphics/view.h>
  9. #include <dos/dos.h>
  10. #include <exec/memory.h>
  11. #include <exec/libraries.h>
  12. #include <exec/types.h>
  13. #include <libraries/iffparse.h>
  14. #include <libraries/amigametaformat.h>
  15. #include <pragmas/intuition_pragmas.h>
  16. #include <pragmas/exec_pragmas.h>
  17. #include <pragmas/dos_pragmas.h>
  18. #include <pragmas/iffparse_pragmas.h>
  19. #include <pragmas/amigametaformat_pragmas.h>
  20. #include <stdio.h>
  21. #include <string.h>
  22.  
  23. extern  struct  Library *SysBase;
  24.  
  25. void main()
  26. {
  27.           APTR        amf;
  28.    struct IFFHandle  *iff;
  29.    struct Screen     *scr;
  30.    struct Window     *wnd;
  31.    struct StoredProperty *sp;
  32.    struct Library    *IFFParseBase;
  33.    struct Library    *AmigaMetaFormatBase;
  34.    struct Library    *IntuitionBase;
  35.    struct Library    *DOSBase;
  36.           STRPTR      arg;
  37.           ULONG      *myarray, function, count, error;
  38.           ULONG      mydata[10], file;
  39.           ULONG      pens[] = { ~0 };
  40.  
  41.    if (DOSBase = OpenLibrary( "dos.library", 37))
  42.    {
  43.        if (IntuitionBase = OpenLibrary( "intuition.library", 37))
  44.        {
  45.            if (IFFParseBase = OpenLibrary( "iffparse.library", 37))
  46.            {
  47.                if (AmigaMetaFormatBase = OpenLibrary( "amigametaformat.library", 6))
  48.                {
  49.                    if (scr = OpenScreenTags( NULL,
  50.                                              SA_Width,-1,
  51.                                              SA_Height,-1,
  52.                                              SA_Depth,4,
  53.                                              SA_Pens,pens,
  54.                                              SA_FullPalette,TRUE,
  55.                                              SA_Type,CUSTOMSCREEN,
  56.                                              SA_SharePens,TRUE,
  57.                                              TAG_DONE))
  58.                    {
  59.                       if (wnd = OpenWindowTags( NULL,
  60.                                                 WA_CustomScreen,scr,
  61.                                                 WA_IDCMP,IDCMP_MOUSEBUTTONS,
  62.                                                 WA_Title,"AMF file viewer (simple)",
  63.                                                 TAG_DONE))
  64.                       {
  65.                           arg = GetArgStr();
  66.                           arg[strlen(arg)-1] = 0;
  67.                           if (file = Open( arg, MODE_OLDFILE))
  68.                           {
  69.                               if (iff = AllocIFF())
  70.                               {
  71.                                   InitIFFasDOS( iff);
  72.                                   iff->iff_Stream = file;
  73.                                   if (!OpenIFF( iff, IFFF_READ))
  74.                                   {
  75.                                       mydata[0] = ID_AMFF;
  76.                                       mydata[1] = ID_VERS;
  77.                                       mydata[2] = ID_AMFF;
  78.                                       mydata[3] = ID_FVER;
  79.                                       mydata[4] = ID_AMFF;
  80.                                       mydata[5] = ID_HEAD;
  81.                                       mydata[6] = ID_AMFF;
  82.                                       mydata[7] = ID_BODY;
  83.                                       if (!PropChunks( iff, (LONG *)mydata, 4))
  84.                                       {
  85.                                           if (!StopChunk( iff, ID_AMFF, ID_BODY))
  86.                                           {
  87.                                               if (!ParseIFF(iff,IFFPARSE_SCAN))
  88.                                               {
  89.                                                   if (sp = FindProp( iff, ID_AMFF, ID_VERS))
  90.                                                   {
  91.                                                       /* nicht sehr elegant, aber funkioniert :-) */
  92.                                                       myarray = (ULONG *)sp->sp_Data;
  93.                                                       printf( "Alte Version: %ld.%ld\n", myarray[0], myarray[1]);
  94.                                                   }
  95.                                                   if (sp = FindProp( iff, ID_AMFF, ID_FVER))
  96.                                                       printf( "Neue Version: %s\n", sp->sp_Data);
  97.                                                   if (sp = FindProp( iff, ID_AMFF, ID_HEAD))
  98.                                                   {
  99.                                                       /* nicht sehr elegant, aber funkioniert :-) */
  100.                                                       myarray = (ULONG *)sp->sp_Data;
  101.                                                       printf( "Dimension: %d x %d\n", myarray[0], myarray[1]);
  102.                                                   }
  103.                                                   mydata[0] = (ULONG )wnd;
  104.                                                   mydata[1] = (ULONG )scr->ViewPort.ColorMap;
  105.                                                   if (amf = AmfOpen( AMF_WINDOW, mydata))
  106.                                                   {
  107.                                                       while (ReadChunkBytes( iff, &function, 4) == 4)
  108.                                                       {
  109.                                                          if (ReadChunkBytes( iff, &count, 4) == 4)
  110.                                                          {
  111.                                                              if (myarray = AllocMem( count*4, MEMF_CLEAR))
  112.                                                              {
  113.                                                                  if (ReadChunkBytes( iff, myarray, count*4) == (count*4))
  114.                                                                  {
  115.                                                                      error = AmfFunction( amf, myarray, function, count);
  116.                                                                      if (error != 0)
  117.                                                                          printf("function:%ld count:%ld error:%ld\n",function,count,error);
  118.                                                                  }
  119.                                                                  FreeMem( myarray, count*4);
  120.                                                              }
  121.                                                          }
  122.                                                       }
  123.                                                       AmfClose(amf);
  124.                                                   }
  125.                                               }
  126.                                           }
  127.                                       }
  128.                                       CloseIFF( iff);
  129.                                   }
  130.                                   FreeIFF( iff);
  131.                               }
  132.                               Close( file);
  133.                            }else
  134.                            {
  135.                                printf( "can`t open file: %s\n" , arg);
  136.                            }
  137.                            WaitPort( wnd->UserPort);
  138.                            CloseWindow( wnd);
  139.                        }else
  140.                        {
  141.                            printf( "no window\n");
  142.                        }
  143.                        CloseScreen( scr);
  144.                    }else
  145.                    {
  146.                        printf( "no screen\n");
  147.                    }
  148.                    CloseLibrary( AmigaMetaFormatBase);
  149.                }else
  150.                {
  151.                    printf( "no amigametaformat.library 6+\n");
  152.                }
  153.                CloseLibrary( IFFParseBase);
  154.            }else
  155.            {
  156.                printf( "no iffparse.library 37+\n");
  157.            }
  158.            CloseLibrary( IntuitionBase);
  159.        }else
  160.        {
  161.            printf( "please use OS 2.0 or better for this\n");
  162.        }
  163.        CloseLibrary( DOSBase);
  164.    }else
  165.    {
  166.        printf( "please use OS 2.0 or better for this\n");
  167.    }
  168. }
  169.  
  170.